{extend  name="manage@public/layout" /}
{block name="style"}
<style>
    .customcb .spot{
        width: 19px;
        height: 19px;
        display: block;
        border:1px solid #cacece;
        cursor: pointer;
        margin-top: -24px;
    }
    .customcb input:checked + .spot{
        border:none;
        background:url("/../../static/css/plugins/iCheck/green.png") no-repeat -48px 0;  /*选中后的样式图片*/
    }
</style>
{/block}
{block name="content"}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>配置渠道 </h5>
                    <div class="ibox-tools">
                        <a href="{:url('/manage/user/agent')}" class="close-link">
                            <i class="fa fa-reply-all">&nbsp;返回</i>
                        </a>
                    </div>
                </div>  
                <div class="ibox-content">
                    <form id="product">
                    <table class="table table-striped table-bordered" cellpadding="1">
                        <tr align="center">
                            <td colspan="1">渠道</td>
                            <td>支付类型</td>
                            
                            <td>最低金额</td>
                            <td>最高金额</td>
                            <td>固定金额</td>
                            <td>倍数金额</td>
                            <td>排除尾数</td>
                            <td>结算方式</td>
                            <td>渠道状态</td>
                            <td>成本费率(%)</td>
                            <td>代理费率(%)</td>
                            <td>选 择</td>
                        </tr>
                        <input type="hidden" name="mch" value="{$info.mch}">
                        {volist name="list" id="vo"}
                        <tr align="center">
                            <td rowspan="{$vo.count+1}">{$vo.title}</td>
                            <tr align="center">
                                {volist name="vo.list" id="v"}
                                <td> {:\\app\\model\\Channel::paymentType($v['pay_type'])} </td>
                                <td> {$v.min_amount|abs|default=''} </td>
                                <td> {$v.max_amount|abs|default=''} </td>
                                <td> {$v.fixed_amount|abs|default=''} </td>
                                <td> {$v.double_amount|abs|default=''} </td>
                                <td> {$v.exclude_tail} </td>
                                <td> {eq name="v.settlement" value="1"}D0{else/}T1{/eq}</td>
                                <td>
                                    <input disabled {eq  name="v.status" value="1"}checked{/eq} data-id="{$vo.id}" type="checkbox" class="js-switch"  />
                                </td>
                                <td> {$v.cost} </td>
                                <td style="text-align: -webkit-center;"> 
                                    <input placeholder="设置费率" style="width:80px;text-align: center;" disabled class="input-sm form-control" type="text" name="act[{$v.id}][agent_rate]" value="{:\\app\\model\\Mch::get_agent_rate($info['id'])}" /> 
                                </td>
                                <input type="hidden" name="act[{$v.id}][channel_id]" value="{$v['channel_id']}" />
                                <td style="text-align: -webkit-center">
                                    <div class="customcb">
                                        <label><input {if condition="in_array($v.id,$info->payment_id)"}checked{/if} class="bt-mch-type" {eq name="v.status" value="2"}disabled{/eq} value="{$v.id}" name="act[{$v.id}][payment_id]"  style='{eq name="v.status" value="2"}cursor:no-drop;{else/}cursor:pointer;{/eq}opacity:0;width:20px;margin:10px 5px 0;height:20px;' type="checkbox" /><em class="spot"></em></label>
                                    </div>
                                </td>
                            </tr>
                            {/volist}
                        </tr>
                        {/volist}
                    </table>
                    {notempty name="list"}
                    <div class="col-sm-12" style="float: none;text-align: right;">
                        <button style="margin:6px 0px;" onclick="checkAll()" type="button" class="btn btn-primary btn-sm">全选/反选</button>
                        <button type="button" class="btn btn-primary bt-agent-p btn-sm">保存</button>
                    </div>
                    {/notempty}
                    </form>
                </div>
            </div>    
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script src="/static/js/admin/mch.js"></script>
<script>
    //全选/取消
    var select = 0;
    function checkAll(){
        select = select ? 0 : 1;
        //全选
        if(select){
            $(".bt-mch-type").each(function(){ 
                
                if(($(this).is(":disabled")) === false){
                    $(this).prop("checked",true);
                } 
            });
            //取消全选
        }else{
            $(".bt-mch-type").prop("checked",false);
        }
    }
    $(".bt-agent-p").click(function(){
        $.ajax({
        type: "POST",//方法类型
        url: "/manage/agentConf" ,//url
        data: $('#product').serialize(),
        beforeSend:function(data){
            $(".bt-agent-p").attr({ disabled: "disabled" });
            index = parent.layer.load(0, {shade: false});//添加加载动画
        },
        success: function (result) {
            parent.layer.msg(result['msg']); 
            if(result['code'] == 1){
                setTimeout(function() {
                    window.location.reload();
                }, 1000)
            }
        },
        error : function() {
            parent.layer.msg("异常！");
        },
        complete: function () {
            parent.layer.close(index);//去掉加载动画 
            $(".bt-agent-p").removeAttr("disabled");
        }
    });
    })
</script>
{/block}

